/**
 * @(#)RetentTaskQueueTimer.java 2017年04月18日
 * Copyright(C) 2017 ZHEXIN IT CO.,LTD. All rights reserved.
 */
package org.jsbd.boss.timer;

import org.jsbd.boss.service.INewTaskService;
import org.jsbd.boss.service.IRetentTaskService;
import org.jsbd.boss.util.CacheKey;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 留存任务队列更新到缓存队列
 * 
 * @author <a href="mailto:xupengcheng@zhexinit.com" >徐鹏程</a>
 * @version 1.0.0
 */
@Service
public class RetentTaskDataSourceTimer extends TaskAdapterHandler {
	public static final Logger LOGGER = LoggerFactory.getLogger(RetentTaskDataSourceTimer.class);

	@Resource(name = "retentTaskService")
	private IRetentTaskService retentTaskService;

	/*
	 * (non-Javadoc)
	 *
	 * @see org.jsbd.boss.timer.TaskHandler#execute()
	 */
	@Override
	public void run() {
		long expireTime = 30;
		Object apkTimeStr = cacheParamManager.getParamValue(CacheKey.RETENT_TASK_QUEUE_REFRESH);
		if (apkTimeStr != null) {
			expireTime = Long.parseLong(apkTimeStr.toString());
		}
		if (redisClient.evalSetNx(CacheKey.RETENT_TASK_QUEUE_LOCK, expireTime)) {
			long start = System.currentTimeMillis();
			retentTaskService.updateTaskOfCache();
			LOGGER.warn("retent task queue of datasource timer {} 秒", (System.currentTimeMillis() - start) / 1000);
		
		}
	}

}
